package com.wuye.action;

import java.util.List;

import lombok.Getter;
import lombok.Setter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.wuye.common.vo.CommonObjectVO;
import com.wuye.services.ParkingTypeServiceManager;

public class ParkingTypeAction extends ActionSupport
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 288988253204802178L;
	private static Logger log = Logger.getLogger(ParkingTypeAction.class);
	@Autowired
	private ParkingTypeServiceManager parkingTypeService;
	
	@Setter
	@Getter
	private String inParma;
	@Setter
	@Getter
	private String rtnMsg;
	
	public String getParkingTypes()
	{
		JSONObject jsonObj = JSONObject.fromObject(inParma);
		
		try 
		{
			int communityId = Integer.parseInt(jsonObj.getString("communityId"));
			
			jsonObj.clear();
			jsonObj.put("found", 1);
			
			List <CommonObjectVO> parkingTypes = parkingTypeService.getParkingTypes(communityId);		
			
			if (parkingTypes != null && parkingTypes.size() > 0)
			{
				jsonObj.put("data", JSONArray.fromObject(parkingTypes).toString());				
			}
			else
			{
				jsonObj.put("found", 0);
			}
		} 
		catch (Exception e) 
		{
			jsonObj.clear();
			jsonObj.put("found", 0);
			e.printStackTrace();
		}
		finally
		{
			rtnMsg = jsonObj.toString();
		}
		
		log.debug(rtnMsg);
		
		return SUCCESS;
	}
	
}
